home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 417_01 / libftp / FtpLibrary.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-24  |  5.3 KB  |  189 lines

  1. /*
  2.               Library for ftpd clients.(libftp)
  3.             Copyright by Oleg Orel
  4.              All rights reserved.
  5.             
  6. This  library is desined  for  free,  non-commercial  software  creation. 
  7. It is changeable and can be improved. The author would greatly appreciate 
  8. any  advises, new  components  and  patches  of  the  existing  programs.
  9. Commercial  usage is  also  possible  with  participation of it's author.
  10.  
  11.  
  12.  
  13. */
  14.   
  15. #ifndef __FTPLIBRARY_H
  16. #define __FTPLIBRARY_H
  17.  
  18.  
  19. #ifdef __cplusplus
  20.     extern "C" {
  21. #endif
  22. #include <stdio.h>
  23. #include <sys/types.h>
  24. #include <sys/socket.h>
  25. #include <arpa/ftp.h>
  26. #include <netinet/in.h>
  27. #include <netdb.h>
  28.  
  29. #ifdef _AIX
  30. int accept (int, struct sockaddr_in*, int*);
  31. char *bcopy (char*, char*, size_t);
  32. int bind (int, const void*, int);
  33. int connect (int, struct sockaddr_in*, int);
  34. int gethostname (char*, size_t);
  35. int getsockname (int, struct sockaddr_in*, int*);
  36. int getpeername (int, struct sockaddr_in*, int*);
  37. int getsockopt (int, int, int, void*, int*);
  38. int listen(int, int);
  39. int setsockopt (int, int, int, (size_t);
  40. int socket (int, int, int);
  41. void free (void*);
  42. void *malloc (size_t);
  43. #endif
  44.  
  45. extern int errno;
  46.         
  47.  
  48.         /* Standard Macros & Definitions */
  49.  
  50.         
  51.       
  52. #define EXIT(con,e) \
  53.   ( con -> errno = e,  \
  54.     ((con->func != NULL) && (e < 0) )?(*(con->func))(con,e,FtpMessage(e)) : 0,\
  55.     ((e==QUIT)&&(con->IO != NULL))?(*(con->IO))(con,errno,strerror(errno)):0,\
  56.      e\
  57.   )
  58.    
  59. #define MAX_ANSWERS 10 /* Number of known goodest answers for reqest */
  60. #define QUIT 0
  61. #define Ctrl(x) ((x) - '@')
  62. #define FREE(x) memset ( &x , '\0' , sizeof x )
  63. #define CUT(x) ((x)&0xff)
  64.  
  65. typedef int STATUS;
  66. typedef char String[256];
  67.  
  68.  
  69.         /* Common Information Structure */
  70.  
  71. typedef struct
  72. {
  73.   int sock;
  74.   FILE *data;
  75.   char mode;
  76.   int errno;
  77.   int ch;
  78.   STATUS (*func)();
  79.   STATUS (*debug)();
  80.   STATUS (*IO)();
  81. } FTP;
  82.  
  83. enum {FTP_nodebug,FTP_debug,FTP_noexit};
  84.  
  85. extern int ftplib_debug;
  86.  
  87. /* Connect & disconnect */ 
  88.  
  89. STATUS  FtpConnect(FTP **con,char *hostname);
  90. #define FtpUser(ftp,user)           FtpCommand(ftp,"USER %s",user,230,331,332,EOF)
  91. #define FtpPassword(ftp,pas)        FtpCommand(ftp,"PASS %s",pas,230,332,EOF)
  92. #define FtpAccount(ftp,acc)         FtpCommand(ftp,"ACCT %s",acc,230,EOF)
  93. STATUS  FtpLogin(FTP **con,char *host ,char *user,char *pass,char *acct);
  94. STATUS  FtpBye (FTP * con);
  95.  
  96. /* Set type of transfer */
  97.  
  98. #define FtpAscii(ftp)               FtpType(ftp,"A")
  99. #define FtpBinary(ftp)              FtpType(ftp,"I")
  100.  
  101.  
  102. /* Receive Procedures */
  103.  
  104. STATUS  FtpRetrTimeout(FTP *con, char *command,char *inp,char *out,long time);
  105. #define FtpRetr(ftp,com,inp,out)    FtpRetrTimeout(ftp,com,inp,out,0)
  106. #define FtpGet(ftp,in,out)          FtpRetr(ftp,"RETR %s",in,out)
  107. #define FtpGetTimeout(ftp,in,out,t) FtpRetrTimeout(ftp,"RETR %s",in,out,t)
  108. #define FtpDirectory(ftp,pat,out)   FtpRetr(ftp,"LIST %s",pat,out)
  109. #define FtpDir(ftp,out)             FtpRetr(ftp,"LIST","",out)
  110.  
  111. /* Send Procedures */
  112.  
  113. STATUS  FtpStorTimeout(FTP *con ,char*command ,char *inp,char *out,long time);
  114. #define FtpStor(ftp,com,inp,out)    FtpStorTimeout(ftp,com,imp,out,0)
  115. #define FtpPut(ftp,in,out)          FtpStor(ftp,"STOR %s",in,out)
  116. #define FtpPutTimeout(ftp,in,out,t) FtpStorTimeout(ftp,"STOR %s",in,out,t)
  117.  
  118. /* Command for remote server for startup transfer */
  119.  
  120. #define FtpGetFile(ftp,file)        FtpCommand(ftp,"RETR %s",file,\
  121.                          200,125,150,250,EOF)
  122. #define FtpPutFile(ftp,file)        FtpCommand(ftp,"STOR %s",file,\
  123.                         200,125,150,250,EOF)
  124.  
  125. /* Command for remote server for startup transfer and make data connection */
  126.  
  127. STATUS  FtpData( FTP * con , char * command , char * param , char *mode);
  128. STATUS  FtpPort ( FTP *con ,int ,int ,int ,int ,int ,int );
  129. #define FtpOpenRead(ftp,file)       FtpData(ftp,"RETR %s",file,"r")
  130. #define FtpOpenWrite(ftp,file)      FtpData(ftp,"STOR %s",file,"w")
  131. #define FtpOpenAppend(ftp,file)     FtpData(ftp,"APPE %s",file,"r")
  132. STATUS  FtpOpenDir( FTP * con , char * files );
  133. STATUS  FtpClose ( FTP *);
  134.  
  135. /* Command for handing transfer */
  136.  
  137. STATUS  FtpGetString ( FTP * con , char * str );
  138. STATUS  FtpRead ( FTP * con);
  139. STATUS  FtpWrite ( FTP * con , char c);
  140.  
  141.  
  142. /* Manipulation commands for remote server */
  143.  
  144. STATUS  FtpCommand ();
  145. #define FtpChdir(ftp,dir)           FtpCommand(ftp,"CWD %s",dir,200,250,EOF)
  146. #define FtpMkdir(ftp,dir)           FtpCommand(ftp,"MKD %s",dir,200,257,EOF)
  147. #define FtpRm(ftp,dir)              FtpCommand(ftp,"DELE %s",dir,200,250,EOF)
  148. char   *FtpPwd(FTP *con);
  149. STATUS  FtpMove ( FTP *con,char * old,char *new);
  150.  
  151. /* Procedures for dialog with remote server */
  152.  
  153. STATUS  FtpInitMessageList();
  154. STATUS  FtpSendMessage( FTP * con , char * Message );
  155. int     FtpGetMessage( FTP * con , char * Message);
  156. char   *FtpMessage(int Number);
  157. int     FtpNumber ( char * Message );
  158.  
  159.  
  160. /* Debug */
  161.  
  162. #define FtpSetErrorHandler(con,f) con->func = f
  163. #define FtpSetDebugHandler(con,f) con->debug = f 
  164. #define FtpSetIOHandler(con,f) con->IO =f
  165. #define FtplibDebug(t) ftplib_debug=t
  166. STATUS  FtpDebugDebug ( FTP *con, int errno, char * Message);
  167. STATUS  FtpDebugError ( FTP *con, int errno, char * Message);
  168. STATUS  FtpDebugIO    ( FTP *con, int errno, char * Message);
  169. void    FtpDebug ( FTP * con );
  170.  
  171.  
  172. /* Other Procedures */
  173.  
  174. FILE   *FtpFullOpen(char * file,char * mode );
  175. FILE   *Ftpfopen(char *filename,char *mode);
  176. STATUS  FtpFullClose(FILE *);
  177. STATUS  FtpGood ();
  178. struct  hostent *FtpGetHost(char *host);
  179.  
  180. #ifdef __cplusplus
  181. }
  182. #endif
  183.       
  184.  
  185. #endif /* __FTPLIBRARYH_ */
  186.  
  187.  
  188.  
  189.